// This code updates the google logo in the main  page to a Kanye West Photo
//var googleLogoDiv = document.getElementById("lga");
//var googleLogo = googleLogoDiv.childNodes[0];
//googleLogo.src = "http://www.thefrugalista.com/wp-content/uploads/2012/01/Kanye-West-.jpg";
//googleLogo.height = 200;
//googleLogo.width = 200;

//Get HTML containing images from a Kanye West photo site
var req = new XMLHttpRequest();
req.open(
    "GET",
    "http://www.starpulse.com/Music/West,_Kanye/Pictures/",
     true);
req.onload = PickPhotoAndShow;
req.send(null);

//Pick one randomly
function PickPhotoAndShow()
{	
	//parse response text to xml
	parser = new DOMParser();
	responseXML = parser.parseFromString(req.responseText, 'text/xml');    
	var photos = responseXML.getElementsByTagName('img');	
		
	photos = FilterPhotos(photos);
	
	//Change Google main page logo to the picture
	var googleLogoDiv = document.getElementById("lga");
	var googleLogo = googleLogoDiv.childNodes[0];	
	googleLogo.src = photos[0].src;
	googleLogo.height = 500;
	googleLogo.width = 500;		
}
//only keep images that look like this
//<img src="http://images.starpulse.com/pictures/2011/12/30/thumbs/Kanye%20West-20111230-12.jpg" alt="Kanye West-20111230-12.jpg">
function FilterPhotos(photos)
{
	var filteredPhotos = new Array(); 
	for(var i=0;i<photos.length;i++)
	{
		var photo = photos[i];
		//regexp pattern for desired kanye photos
		var patt=new RegExp("Kanye");
		if(patt.exec(photo.alt))
		{
			filteredPhotos.push(photo);			
		}
	}	
	return filteredPhotos;
}

